<?php

class DataSet{
	private $records = Array();
	private $dbLink = NULL;
	public function __construct(){
		$this->dbLink = DB::getInstance();
	}
	public function Load($ModelClass,$WhereKeyValues=false){
		$query = "select * from " . $ModelClass;
		if($WhereKeyValues){
			$columnValues= Array();
			foreach ($WhereKeyValues as $column=>$value){
				$columnValues[] = "$column = ". DB::EscapeValue($value);
			}
		
		
			$query.= " where ". implode($columnValues," AND ");
		}
		//echo $query;
		$result = $this->dbLink ->query( $query);
		$this->records = Array();
		while ($line = $this->dbLink->fetchNextObject($result)) {
			//echo $line->id;
			$this->records[] = new $ModelClass($line);
		}
		
		return $this->GetRecords();
		
		//foreach($this->records as $model){
		//	echo $model->ToString();
		//}
	}
	
	public function GetRecords(){
		return $this->records;
	}
	
	
	
}

?>
